package com.ltmall.api.manager.impl;

import com.ltmall.api.bean.Goods;
import com.ltmall.api.bean.ThDirectSupplyGoods;
import com.ltmall.api.bean.ThSku;
import com.ltmall.api.dao.impl.DirectSupplyGoodsDAO;
import com.ltmall.api.dao.impl.GoodsDAO;
import com.ltmall.api.manager.DirectSupplyGoodsManager;

import java.util.ArrayList;
import java.util.List;

public class DirectSupplyGoodsManagerImpl implements DirectSupplyGoodsManager {

    private DirectSupplyGoodsDAO directSupplyGoodsDAO;

    private GoodsDAO             goodsDAO;

    @Override
    public int getUserGroupBuyingAmount(int directSupplyId, int userId) {
        return directSupplyGoodsDAO.getUserGroupBuyingAmount(directSupplyId, userId);
    }

    @Override
    public List<Goods> getGoodsByDirectSupply(int directSupplyId, String directType) {

        //【1】查询该小区下关联的商品编号列表
        List<ThDirectSupplyGoods> directSupplyGoods = directSupplyGoodsDAO.getGoodsByDirectSupply(
            directSupplyId, directType);

        //【2】查询商品信息
        List<Goods> goodList = new ArrayList<Goods>();
        if (directSupplyGoods != null) {
            for (ThDirectSupplyGoods supplyGoods : directSupplyGoods) {
                //商品详情
                Goods good = goodsDAO.goodsDetail(supplyGoods.getGoodId());

                //sku信息
                if (good != null && good.getStation() == 1 && good.getShow() == 1) {
                    List<ThSku> price = goodsDAO.getPrice(supplyGoods.getGoodId());
                    good.setThSkus(price);
                    goodList.add(good);
                }
            }
        }

        return goodList;
    }

    @Override
    public boolean save(ThDirectSupplyGoods info) {
        return directSupplyGoodsDAO.save(info);
    }

    @Override
    public List<ThDirectSupplyGoods> getGoodsByDirectSupplyAndGoodId(int directSupplyId, int goodId) {
        return directSupplyGoodsDAO.getGoodsByDirectSupplyAndGoodId(directSupplyId, goodId);
    }

    @Override
    public boolean delete(int id) {
        return directSupplyGoodsDAO.delete(id);
    }

    @Override
    public boolean deleteByGoodId(int goodId) {
        return directSupplyGoodsDAO.deleteByGoodId(goodId);
    }

    /**
     * @param directSupplyGoodsDAO the directSupplyGoodsDAO to set
     */
    public void setDirectSupplyGoodsDAO(DirectSupplyGoodsDAO directSupplyGoodsDAO) {
        this.directSupplyGoodsDAO = directSupplyGoodsDAO;
    }

    /**
     * @param goodsDAO the goodsDAO to set
     */
    public void setGoodsDAO(GoodsDAO goodsDAO) {
        this.goodsDAO = goodsDAO;
    }

}
